package com.jd.rapid.rpc.config.provider;

import com.jd.rapid.rpc.server.RpcServer;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.List;


/**
 * 服务器端启动配置类
 */
@Data
@Slf4j
public class RpcServerConfig {


    private final String host="127.0.0.1";

    protected  int port;

    private List<ProviderConfig> providerConfigs;

    private RpcServer rpcServer=null;


    public RpcServerConfig( List<ProviderConfig> providerConfigs) {
        this.providerConfigs = providerConfigs;
    }

    public void exporter(){
        if(rpcServer==null){
            try {
                rpcServer=new RpcServer(host+":"+port);
            } catch (InterruptedException e) {
                e.printStackTrace();
                log.error("RpcServerConfig exporter exception:{}",e);
            }
            for(ProviderConfig pc:providerConfigs){
                rpcServer.registerProccessor(pc);
            }
        }
        //zk  作业一
        //把所有服务提供的列表注册到zk上
        /**
         * /dubbo
         *      /interface: com.bfxy.service.helloService
         *          /providers
         *             /ip:port(192.168.11.101:8765)
         *             /ip:port(192.168.11.102:8765)
         *          /consumers
         *              /ip:port
         *              /ip:port
         */

    }

}
